package com.fancy.learncenter.ui.adapter;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.fancy.learncenter.R;
import com.fancy.learncenter.bean.CartoonRealeaseSpeakDataBean;
import com.fancy.learncenter.common.Constant;
import com.fancy.learncenter.ui.activity.CartoonDetailActivity;
import com.fancy.learncenter.ui.adapter.base.CommonRecycleViewAdapter;
import com.fancy.learncenter.ui.adapter.base.CustomViewHold;
import com.fancy.learncenter.ui.fragment.CartoonSentenceSpeakFragment;
import com.fancy.learncenter.utils.DataUtil;
import com.fancy.learncenter.utils.FileUtils;
import com.fancy.learncenter.utils.LogUtil;
import com.fancy.learncenter.utils.TimeUtil;
import com.fancy.learncenter.utils.ToastUtil;
import com.fancy.learncenter.utils.Utils;

import java.io.File;
import java.util.List;

/**
 * Created by shiweiwei on 2017/12/7.
 */

public class CartoonListenLocalAdapter extends CommonRecycleViewAdapter<CartoonRealeaseSpeakDataBean.ResultBean> {

    public CartoonListenLocalAdapter(Context mContext, List<CartoonRealeaseSpeakDataBean.ResultBean> itemDatas) {
        super(mContext, R.layout.fragment_cartoon_local_item, itemDatas);
    }


    @Override
    public void bindView(CustomViewHold customViewHold, final CartoonRealeaseSpeakDataBean.ResultBean item, final int position) {
        TextView title = customViewHold.getView(R.id.title);
        title.setText(item.getQuestionName());

        TextView duration = customViewHold.getView(R.id.duration);
//        duration.setText(TimeUtil.localDubTimeLength(Integer.parseInt(item.getResourceDuration()))+"");

        TextView time = customViewHold.getView(R.id.time);
        time.setText(item.getCommitTime());

        SimpleDraweeView simpleDraweeView = customViewHold.getView(R.id.simpleDraweeView);
        simpleDraweeView.setImageURI(item.getCoverImgUrl());

        String locaPath = filePath + item.getSubjectQuestionId() + Constant.DIVID_CODE + item.getCommitTime().split(" ")[0] + "_release" + "/";
        customViewHold.getRoorView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext, CartoonDetailActivity.class);
//                if (TextUtils.isEmpty(filePath)) {
//                    intent.putExtra(CartoonDetailActivity.LOCAL_FILE_PATH, FileUtils.getEveryDayRecorderAudioPath() + item.getSubjectQuestionId() + Constant.DIVID_CODE + item.getCommitTime().split(" ")[0] + "/");
//
//                } else {
//
//                }
                intent.putExtra(CartoonDetailActivity.LOCAL_FILE_PATH, filePath + item.getSubjectQuestionId() + Constant.DIVID_CODE + item.getCommitTime().split(" ")[0] + "_release" + "/");
                intent.putExtra(CartoonDetailActivity.QUESTION_ID, item.getSubjectQuestionId());
                intent.putExtra(CartoonDetailActivity.ANSWER_KEY, item.getLocalResourceUrl());
                mContext.startActivity(intent);

            }
        });

        customViewHold.getRoorView().setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {

                if (deleteCallBack != null) {
                    deleteCallBack.deleCallBack(position);
                }

                return true;
            }
        });
    }

    private String filePath;

    public String getFilePath() {
        return filePath;
    }

    public void setFilePath(String filePath) {
        this.filePath = filePath;
    }

    private DeleteCallBack deleteCallBack;

    public DeleteCallBack getDeleteCallBack() {
        return deleteCallBack;
    }

    public void setDeleteCallBack(DeleteCallBack deleteCallBack) {
        this.deleteCallBack = deleteCallBack;
    }

    public interface DeleteCallBack {
        abstract void deleCallBack(int position);
    }
}
